import axiosInstance from '@/api/axiosInstance'

// 定义查询参数对象
interface roleListParams {
  name?: string
  page?: number
  pageSize?: number
  // 其他查询条件...
}

/**
 * 获取列表
 */
export const getRoleList = async (params?: roleListParams) => {
  return axiosInstance.get('/admin/role', { params })
}

/**
 * 创建
 */
export const createRole = async (data: any) => {
  return axiosInstance.post('/admin/role', data)
}

export const getRoleDetail = async (id: number) => {
  return axiosInstance.get(`/admin/role/${id}`)
}

export const updateRole = async (id: number, data: any) => {
  return axiosInstance.put(`/admin/role/${id}`, data)
}

/**
 * 删除角色
 * @param id
 */
export const deleteRole = async (id: number) => {
  return axiosInstance.delete(`/admin/role/${id}`)
}
/**
 * 获取角色选项
 */
export const getRoleOptions = async () => {
  return axiosInstance.get('/admin/role/options')
}

/**
 * 获取指定角色的菜单集合
 */
export const getRoleMenuIds = async (id: number) => {
  return axiosInstance.get(`/admin/role/${id}/menus`)
}

/**
 * 为角色分配菜单
 */
export const assignRoleMenus = async (id: number, data: any) => {
  return axiosInstance.post(`/admin/role/${id}/assign-menus`, data)
}

/**
 * 获取指定角色的权限集合
 */
export const getRolePermissions = async (id: number) => {
  return axiosInstance.get(`/admin/role/${id}/permissions`)
}

/**
 * 为角色分配权限
 */
export const assignRolePermission = async (id: number, params: any) => {
  return axiosInstance.post(`/admin/role/${id}/assign-permissions`, params)
}
